package com.jvm;

public class YoungGenGC {
	public static OOMObject oom; 
	
	public static void main(String[] args) {
		System.out.println(Runtime.getRuntime().freeMemory()/1024/1024/8 +"G") ;
		System.out.println(Runtime.getRuntime().totalMemory()/1024/1024/8 +"G");
		System.out.println(Runtime.getRuntime().maxMemory()/1024/1024 +"G");
//
//		YoungGenGC.oom = new OOMObject();
//		oom = null;
//		System.gc();
//		System.out.println("GC");
////		try {
////			Thread.sleep(500);
////		} catch (InterruptedException e) {
////			e.printStackTrace();
////		}
//		if (oom != null) {
//			oom.isALive("");
//		}else  {
//			System.out.println("Dead");
//		}
		
	}

	static class OOMObject {

		public void isALive(String str) {
			System.out.println("我还 活着！"+ str);
		}

		@Override
		protected void finalize() throws Throwable {
			System.out.println("finalize method is executed!");
			YoungGenGC.oom = this;
			super.finalize();
		}
		
	}
}
